public class TestBinaryTree {
    static class TreeNode {
        public char val;
        public TreeNode left;
        public TreeNode right;

        public TreeNode(char val) {
            this.val = val;
        }
    }

    public void createTree() {
        TreeNode A = new TreeNode('A');
        TreeNode B = new TreeNode('B');
        TreeNode C = new TreeNode('C');
        TreeNode D = new TreeNode('D');
        TreeNode E = new TreeNode('E');
        TreeNode F = new TreeNode('F');
        TreeNode G = new TreeNode('G');
        TreeNode H = new TreeNode('H');


    }

    public void preOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        System.out.println(root.val + " ");
        preOrder(root.left);
        preOrder(root.right);
    }

    public void inOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        inOrder(root.left);
        System.out.println(root.val + " ");
        inOrder(root.right);
    }
    public void postOrder(TreeNode root) {
        if(root == null) {
            return;
        }
        postOrder(root.left);
        postOrder(root.right);
        System.out.println(root.val + " ");
    }

    public static int nodeSize = 0;
    public int size(TreeNode root) {
        if(root == null) {
            return 0;
        }
        int tmp = size(root.left) +size(root.right) + 1;
        return tmp;
    }

    public static int leafSize = 0;
    public int leafSize(TreeNode root) {
        if(root == null) {
            return 0;
        }
        if(root.left == null && root.right == null) {
            return 1;
        }
        int tmp = leafSize(root.left) + leafSize(root.right);
        return tmp;
    }

    public int getKLevelNodeCount(TreeNode root,int k) {
        if(root == null || k <= 0) {
            return 0;
        }
        if(k == 1) {
            return 1;
        }
        int tmp = getKLevelNodeCount(root.left,k-1) + getKLevelNodeCount(root.right,k-1);
        return tmp;
    }

    public int getHeight(TreeNode root) {  //获取二叉树高度
        if(root == null) {
            return 0;
        }
        int leftHeight = getHeight(root.left);
        int rightHeight = getHeight(root.right);
        return leftHeight > rightHeight ? leftHeight+1 : rightHeight+1;
    }

    public TreeNode find(TreeNode root,char val) {   //查找元素
        if(root == null) {
            return null;
        }
        if(root.val == val) {
            return root;
        }
        TreeNode ret1 = find(root.left,val);
        if(ret1 != null) {   //说明找到了
            return ret1;
        }
        TreeNode ret2 = find(root.left,val);
        if(ret2 != null) {   //说明找到了
            return ret2;
        }
        return null;   //没找到
    }



}
